1
'****************************** Module Header ******************************\
2 ' Module Name: Client.vb
3 ' Project: VBASPNETReverseAJAX
4 ' Copyright (c) Microsoft Corporation
6 ' Client class is used to synchronize the message sending and the message receiving.
7 ' When DequeueMessage method is called, the method will wait until a new message
8 ' is inserted by calling EnqueueMessage method. This class benefits ManualResetEvent
9 ' class to achieve the synchronism.
11 ' This source is subject to the Microsoft Public License.
12 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
13 ' All other rights reserved.
15 '*****************************************************************************/
17 Imports System
.Collections
.Generic
18 Imports System
.Threading
21 ''' This class represents a web client which can receive messages.
24 Private messageEvent
As New ManualResetEvent(False)
25 Private messageQueue
As New Queue(Of Message
)()
28 ''' This method is called by a sender to send a message to this client.
30 ''' <param name="message">the new message</param>
31 Public Sub EnqueueMessage(ByVal message
As Message
)
33 messageQueue
.Enqueue(message
)
35 ' Set a new message event.
41 ''' This method is called by the client to receive messages from the message queue.
42 ''' If no message, it will wait until a new message is inserted.
44 ''' <returns>the unread message</returns>
45 Public Function DequeueMessage() As Message
46 ' Wait until a new message.
47 messageEvent
.WaitOne()
50 If messageQueue
.Count
= 1 Then
53 Return messageQueue
.Dequeue()